package com.datong.server.strategy;

import com.datong.server.strategy.calculatePrice.DiscountCashStrategy;
import com.datong.server.strategy.calculatePrice.NormalCashStrategy;
import com.datong.server.strategy.calculatePrice.ReturnCashStrategy;
import com.datong.server.strategy.calculatePrice.StrategyCash;
import java.util.Map;


public class ContextStrategy {
    private StrategyCash strategyCash;
    public ContextStrategy(Map<String,Double> settlement){
        double discount = settlement.get("discount");
        double retCashSign = settlement.get("retCashSign");
        if(discount == 0 && retCashSign == 0){
            this.strategyCash = new NormalCashStrategy();
        }else if(discount >= 1 && retCashSign == 0){
            this.strategyCash = new DiscountCashStrategy(discount);
        }else if(retCashSign ==1 && discount == 0){
            double condition = settlement.get("condition");
            double retCashPrice = settlement.get("retCash");
            this.strategyCash = new ReturnCashStrategy(condition,retCashPrice);
        }else{
            System.out.println("类型不存在.");
        }

        strategyCash.setNumber(settlement.get("unit"));
        strategyCash.setUnit(settlement.get("number"));
    }
    public double ContextInterface(){
        return strategyCash.getResult();
    }
}
